package com.jf.apply_car.controller;

import com.jf.apply_car.bean.Apply;
import com.jf.apply_car.service.ApplyService;
import com.jf.apply_car.util.ResultJson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/apply")
public class ApplyController {
    private final ApplyService applyService;

    public ApplyController(ApplyService applyService) {
        this.applyService = applyService;
    }

    @GetMapping("/apply")
    public String apply() {
        return "apply/apply";
    }

    @PostMapping("/apply")
    @ResponseBody
    public ResultJson apply(Apply apply) {
        applyService.apply(apply);
        return ResultJson.success();
    }

    @GetMapping("/my/list")
    public String myList() {
        return "apply/apply-my-list";
    }

    @GetMapping("/my/page")
    @ResponseBody
    public ResultJson myPage(int page, int limit, Apply apply) {
        return applyService.getMineApplyPage(page, limit, apply);
    }

    @PostMapping("/delete")
    @ResponseBody
    public ResultJson delete(int[] ids) {
        applyService.delete(ids);
        return ResultJson.success();
    }

    @GetMapping("/list")
    public String list() {
        return "apply/apply-list";
    }

    @GetMapping("/page")
    @ResponseBody
    public ResultJson page(int page, int limit, Apply apply) {
        return applyService.getAllPage(page, limit, apply);
    }
}
